﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using Microsoft.SharePoint;
using System.Windows;

namespace SharePointCommander.Model.TreeView
{
    public class SCSite : SCTreeViewItem<SPSite>
    {
        public SCSite(SCTreeViewItem parent, SPSite site)
            : base(parent, site)
        {
            Header = site.Url;
            IsExpanded = false;
            Expanded += new RoutedEventHandler(SCSite_Expanded);
            ItemsSource = new object[] { null };
        }

        void SCSite_Expanded(object sender, RoutedEventArgs e)
        {
            TreeViewItem item = e.Source as TreeViewItem;
            if (item.ItemsSource.Cast<object>().Contains(null))
            {
                item.ItemsSource = new[] { 
                    new SCWeb(this, SPObject.RootWeb) as TreeViewItem
                };
            }
        }
    }
}
